package com.scott.api.curator;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * Curator 连接工具类
 *
 * @author Scott 2017/11/2 15:49
 */
public class CuratorClientUtils {

    private static CuratorFramework curatorFramework;

    /**
     * zookeeper 连接字符串
     */
    private final static String CONNECT_STRING = "192.168.1.113:2181,192.168.11.104:2181";

    /**
     * 获取连接方法
     *
     * @return CuratorFramework
     */
    public static CuratorFramework getInstance() {
        //fluent风格
        CuratorFramework curatorFramework = CuratorFrameworkFactory.builder()
                .connectString(CONNECT_STRING)
                .sessionTimeoutMs(5000)
                .connectionTimeoutMs(5000)
                .retryPolicy(new ExponentialBackoffRetry(1000, 3))
                .build();
        curatorFramework.start();
        return curatorFramework;
    }
}
